﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace KWT.DRG_DIP.API.Migrations
{
    /// <inheritdoc />
    public partial class _20250408112216 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "User_Area");

            migrationBuilder.DropTable(
                name: "User_Dept");

            migrationBuilder.DropTable(
                name: "User_Role");

            migrationBuilder.DropColumn(
                name: "AreaID",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "Code",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "Code1",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "Code2",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "IsGroup",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "Name1",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "Name2",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "PID",
                table: "Sys_Dept");

            migrationBuilder.DropColumn(
                name: "Icon",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "ParentID",
                table: "Sys_Category");

            migrationBuilder.AlterTable(
                name: "Sys_Dept",
                comment: "部门",
                oldComment: "科室")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterTable(
                name: "Sys_Category",
                comment: "科别",
                oldComment: "")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "名称",
                oldClrType: typeof(string),
                oldType: "varchar(256)",
                oldMaxLength: 256,
                oldDefaultValue: "",
                oldComment: "院内科室名称")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "DeptID",
                table: "Sys_Dept",
                type: "varchar(255)",
                nullable: false,
                comment: "主键",
                oldClrType: typeof(string),
                oldType: "varchar(255)",
                oldComment: "科室主键")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "院内科室名称",
                oldClrType: typeof(string),
                oldType: "varchar(256)",
                oldMaxLength: 256,
                oldDefaultValue: "",
                oldComment: "")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "CategoryID",
                table: "Sys_Category",
                type: "varchar(255)",
                nullable: false,
                comment: "科别主键",
                oldClrType: typeof(string),
                oldType: "varchar(255)",
                oldComment: "")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "AreaID",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "院区")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Code",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "院内科室代码")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Code1",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标一级代码")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Code2",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标二级代码")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<bool>(
                name: "IsGroup",
                table: "Sys_Category",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "是否为医疗组");

            migrationBuilder.AddColumn<string>(
                name: "Name1",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标一级名称")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Name2",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标二级名称")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "PID",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "父键")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Dept_Role",
                columns: table => new
                {
                    DRID = table.Column<string>(type: "varchar(255)", nullable: false, comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeptID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RoleID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Dept_Role", x => x.DRID);
                },
                comment: "部门角色-关系表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "User_AreaRoleDeptCategory",
                columns: table => new
                {
                    UAID = table.Column<string>(type: "varchar(255)", nullable: false, comment: "主键")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UserID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    AreaID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RoleID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeptID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CategoryID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User_AreaRoleDeptCategory", x => x.UAID);
                },
                comment: "用户-院区角色部门科别 关系表")
                .Annotation("MySql:CharSet", "utf8mb4");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Dept_Role");

            migrationBuilder.DropTable(
                name: "User_AreaRoleDeptCategory");

            migrationBuilder.DropColumn(
                name: "AreaID",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "Code",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "Code1",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "Code2",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "IsGroup",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "Name1",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "Name2",
                table: "Sys_Category");

            migrationBuilder.DropColumn(
                name: "PID",
                table: "Sys_Category");

            migrationBuilder.AlterTable(
                name: "Sys_Dept",
                comment: "科室",
                oldComment: "部门")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterTable(
                name: "Sys_Category",
                comment: "",
                oldComment: "科别")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "院内科室名称",
                oldClrType: typeof(string),
                oldType: "varchar(256)",
                oldMaxLength: 256,
                oldDefaultValue: "",
                oldComment: "名称")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "DeptID",
                table: "Sys_Dept",
                type: "varchar(255)",
                nullable: false,
                comment: "科室主键",
                oldClrType: typeof(string),
                oldType: "varchar(255)",
                oldComment: "主键")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "AreaID",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "院区")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Code",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "院内科室代码")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Code1",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标一级代码")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Code2",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标二级代码")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<bool>(
                name: "IsGroup",
                table: "Sys_Dept",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "是否为医疗组");

            migrationBuilder.AddColumn<string>(
                name: "Name1",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标一级名称")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Name2",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "国标二级名称")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "PID",
                table: "Sys_Dept",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "父键")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "",
                oldClrType: typeof(string),
                oldType: "varchar(256)",
                oldMaxLength: 256,
                oldDefaultValue: "",
                oldComment: "院内科室名称")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "CategoryID",
                table: "Sys_Category",
                type: "varchar(255)",
                nullable: false,
                comment: "",
                oldClrType: typeof(string),
                oldType: "varchar(255)",
                oldComment: "科别主键")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Icon",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "ParentID",
                table: "Sys_Category",
                type: "varchar(256)",
                maxLength: 256,
                nullable: false,
                defaultValue: "",
                comment: "")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "User_Area",
                columns: table => new
                {
                    UAID = table.Column<string>(type: "varchar(255)", nullable: false, comment: "主键")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    AreaID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UserID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User_Area", x => x.UAID);
                },
                comment: "用户-院区 关系表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "User_Dept",
                columns: table => new
                {
                    UDID = table.Column<string>(type: "varchar(255)", nullable: false, comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeptID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UserID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User_Dept", x => x.UDID);
                },
                comment: "用户-科室 关系表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "User_Role",
                columns: table => new
                {
                    URID = table.Column<string>(type: "varchar(255)", nullable: false, comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RoleID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UserID = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false, defaultValue: "", comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_User_Role", x => x.URID);
                },
                comment: "用户-角色 关系表")
                .Annotation("MySql:CharSet", "utf8mb4");
        }
    }
}
